<!-- 文章导入管理 -->
<template>
  <div class="import_article">
    <!-- <dt-search ref="search" :labelWidth="60">
    </dt-search> -->
    <div class="flex flex-horizontal-between">
      <Button
        type="primary"
        @click="exportFun"
        class="aciton"
        style="z-index: 99"
        v-if="(!orgId && unlocking('0107090200')) || (orgId && unlocking('0207030302'))">
        导出
      </Button>
      <Button type="primary">
        <a
          href="https://images.tospurfang.com/doc/%E5%8F%91%E6%96%87%E7%AB%A0%EF%BC%88%E5%85%AC%E4%BC%97%E5%8F%B7%E6%96%87%E7%AB%A0%E8%BD%AC%E5%8F%91%EF%BC%89%E6%93%8D%E4%BD%9C%E6%8C%87%E5%BC%95.pdf"
          style="color: #fff"
          target="_blank">
          查看操作指引
        </a>
      </Button>
    </div>
    <dt-grid ref="table" :page="page" :onFetch="onFetch" :select="{ sort: sortCase }" />
    <detail-modal ref="detailModal" />
  </div>
</template>

<script>
  import searchOpt from './opt/search'
  import Column from './opt/column.js'
  import importApi from '@/biz/article/importArticle'
  import detailModal from './component/detailModal'
  export default {
    components: { detailModal },
    data() {
      return {
        pyqVisitCountType: '',
        visitCountType: '',
        orgId: '',
        page: {
          current: 1
        },
        filterParams: {}
      }
    },
    methods: {
      sortCase(sort) {
        console.log(sort)
        if (sort.prop == '_txt_viewCount') {
          this.visitCountType = sort.order == 'desc' ? 2 : sort.order == 'asc' ? 1 : ''
        } else {
          this.visitCountType = ''
        }
        if (sort.prop == '_txt_pyqViewCount') {
          this.pyqVisitCountType = sort.order == 'desc' ? 2 : sort.order == 'asc' ? 1 : ''
        } else {
          this.pyqVisitCountType = ''
        }
        this.$refs.table.fetch()
      },
      onFetch(data) {
        let params = {
          ...data,
          deleteFlag: data.deleteFlag || '',
          buildingId:
            this.$tool.getStorage('isbuildFlag') == 'buildpage' ? this.$dt.buildInfo().housesId : '',
          orgId: this.orgId || '',
          visitCountType: this.visitCountType || '',
          pyqVisitCountType: this.pyqVisitCountType || ''
        }
        this.filterParams = params
        return importApi.pageListWeb({ ...params }).then((res) => {
          console.log(res)
          return res
        })
      },
      init(orgId) {
        this.orgId = orgId
        this.$refs.table.init(this, new Column(this))

        this.$refs.table.fetch(true)
      },
      delFun(data) {
        this.$Modal.confirm({
          title: '是否删除',
          content: '删除文章后，已分享的文章将不能被查看，是否确认删除？',
          okText: '删除',
          cancelText: '取消',
          onOk: () => {
            importApi.importArticleDelete({ id: data.id }).then((res) => {
              this.$refs.table.fetch()
            })
          }
        })
      },
      viewFun(data) {
        this.$refs.detailModal.show(data.id)
      },
      exportFun() {
        let params = this.filterParams
        params.type = this.$tool.getStorage('isbuildFlag') == 'buildpage' ? 1 : 2
        importApi.pageListWebExport({ ...params })
      }
    },
    mounted() {
      if (this.$tool.getStorage('isbuildFlag') == 'buildpage') {
        this.$refs.table.init(this, new Column(this))
        this.$refs.table.fetch()
      }
    }
  }
</script>
<style lang="scss" scoped>
  .import_article {
    padding: 20px;
  }
</style>
